const express = require( 'express' );

const port = 8080 ;
const app = express();

let staticMiddleware = express.static( 'public' );
app.use( staticMiddleware );

let bodyParseMiddleware = express.urlencoded( { extended: false } );
app.use( bodyParseMiddleware );

let middleware = (req,resp)=>{
    console.log( req.method , req.url , req.protocol );
    console.log( 'queryString : ' , req.query );
    console.log( req.query.username );
    console.log( 'requestBody : ' , req.body );
    // 通过 req.params 可以获取所有的 路径变量
    console.log( 'path variable : ' , req.params );
    
    resp.send( `<div>${new Date().toISOString()}</div>`);
}

// 采用 :id 形式可以声明路径变量( Path Variable )
app.use( '/sign/up/:id/:gender' , middleware );

app.listen( port , ()=>{
    console.log( `正在监听${port}端口` );
} );